package org.pearl.thread.demo.test001;

import java.util.concurrent.TimeUnit;

/**
 * Created by TD on 2021/4/13
 */
public class JoinThreadTest001 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "正在检测心跳");
        }, "线程001");

        Thread t2 = new Thread(() -> {
            try {
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "正在检测心跳");
        }, "线程002");
        t2.start();
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t1.start();
    }
}
